Public Class frmBuscarSupervisor
    Public SupervisorSeleccionado As New CNG.Supervisor
    Public ParametroActivo As System.Nullable(Of Boolean) = Nothing
    Public ParametroCodigoCD As String

#Region "Eventos"

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click

        Me.Buscar()

    End Sub

    Private Sub btnSeleccionar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeleccionar.Click

        Me.Seleccionar()

    End Sub

    Private Sub dgrTabla_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgrGrilla.CellDoubleClick

        Me.Seleccionar()

    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub

    Private Sub txtCriterio_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCriterio.KeyPress
        If Asc(e.KeyChar) = Keys.Enter Then
            Me.Buscar()
        End If
    End Sub
    Private Sub dgrGrilla_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgrGrilla.KeyDown

        If e.KeyCode = Keys.Enter Then
            Me.Seleccionar()
        End If

    End Sub
    Private Sub frmBuscarSupervisor_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If Keys.Escape = Convert.ToInt32(e.KeyChar) Then

            Me.Close()

        End If
    End Sub

#End Region

#Region "Procedimientos"
    Private Sub Buscar()

        Dim criterio As String = Me.txtCriterio.Text
        Dim Comando As New CAD.Supervisor.Supervisor_SEARCH(CAD.BaseDatos.Conexion)
        Dim Tabla As New DataTable

        Try
            Comando.LoadTable(Tabla, Me.ParametroCodigoCD, criterio.Trim, ParametroActivo)

            Me.dgrGrilla.DataSource = Tabla
            Me.MostrarCadenaResultados(Tabla.Rows.Count)

        Catch ex As Exception

            MessageBox.Show(ex.Message, "Busqueda Supervisor", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try
    End Sub
    Private Sub Seleccionar()
        Dim i As Integer

        If Me.dgrGrilla.CurrentCell Is Nothing = False Then

            i = Me.dgrGrilla.CurrentRow.Index

            SupervisorSeleccionado = New CNG.Supervisor()

            SupervisorSeleccionado.CodigoCD = Me.dgrGrilla("CodigoCD", i).Value
            SupervisorSeleccionado.Codigo = Me.dgrGrilla("Codigo", i).Value
            SupervisorSeleccionado.Nombre = Me.dgrGrilla("Nombre", i).Value
            SupervisorSeleccionado.Activo = Me.dgrGrilla("Activo", i).Value         
            SupervisorSeleccionado.Telefono = Me.dgrGrilla("Telefono", i).Value

            Me.DialogResult = Windows.Forms.DialogResult.OK
            Me.Close()

        End If
    End Sub


#End Region
End Class
